<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>成长记录-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="sp_tab" style="border-bottom: 2px solid #e5e5e5; background: #fff;">
              <a onclick="back()" class="icon icon-109 f-gray" style="left: 10px;width: 40px;position: absolute;top: 15px;"></a>
              <ul>
                <li class="l_bull tab5 f-16"><a>每周点评</a></li>
                <li class="m_gry tab3 f-16"><a>考试成绩</a></li>
                <li class="r_gry tab4 f-16"><a>荣誉奖励</a></li>
              </ul>
            </div>
            <div class="weui_tab kcfd-list1" id="tab5">
	            <div class="weui_tab_bd">
	            	<div class="weui-header"> 
				  		<h1 class="weui-header-title f-green">${term.termName }</h1>
				    </div>
				    <div class="weui_tab ltbg-content">
			            <div class="weui_navbar">
			                <div class="weui_navbar_item" id="dwspList">
			                    	未回评
			                </div>
			                <div class="weui_navbar_item" id="wyspList">
			                    	已回评
			                </div>
			            </div>
			            <div class="weui_tab_bd">
			                
				            <div class="weui_panel weui_tab_bd_item mt0 mb55">
					            <div class="weui_panel_bd">
					            	<div class="weui_cells weui_cells_access mt0" id="dListTable">
					            	
					            	</div>
					            </div>
					            <div class="dropload-down">
								    <div class="loadData dropload-hasData">点击加载更多数据...</div>
								</div>
				            </div>
					        
				            <div class="weui_panel weui_tab_bd_item mt0">
					            <div class="weui_panel_bd">
					                <div class="weui_cells weui_cells_access mt0" id="yListTable">
					            	
					            	</div>
					            </div>
					            <div class="dropload-down">
								    <div class="loadData dropload-hasData">点击加载更多数据...</div>
								</div>
				            </div>
				            
				            <script id="office-table-template" type="text/x-handlebars-template">
								{{#each rows}}
								<a class="weui_cell weui_media_box weui_media_text" href="<%=basePath%>${user.currUrl}/week/comment/detail/{{id}}?sid={{studentId}}">                        
									<div class="weui_cell_bd weui_cell_primary">                    		
										<h4 class="weui_media_title">{{studentName}}同学的第{{weekNo}}周点评</h4>                    		
										<p class="weui_media_desc">{{teacherCommentContent}}</p>                    		
										<p class="weui_media_desc mt10">发布时间：{{dateFormat teacherCommentTime}}</p>                		
									</div>                		
									<span class="weui_cell_ft"></span>            		
								</a>
								{{/each}}
							</script>
			            </div>
			        </div>
	            </div>
	        </div>
            <div class="weui_tab kcfd-list1 hide" id="tab3">
	            <div class="weui_tab_bd">
		            <div class="weui_panel weui_tab_bd_item qingjia">
			            <div class="weui_panel_bd">
		                    <div class="weui_cells weui_cells_access mt0" id="scoreList">
		                    	
		                    </div>
		                    
		                    <script id="studentScore-table-template" type="text/x-handlebars-template">
		                    {{#each list}}
			                    <div class="weui_cell_bd weui_cell_primary">           
			                   	     <div class="cj_main">
								        <div class="head">
								          <ul>
								            <li>
												<h3>{{examName}}</h3>
												<a href="<%=basePath%>${user.currUrl}/student/groupup/scoreReport/{{examId}}?from=sys&sid=${studentId}" class="score-report">
													<img src="<%=basePath%>/images/huojiangdengji@3x.png" style="height: 18px;"> 成绩分析
												</a>
											</li>
								            <li><span>{{termName}}</span></li>
								          </ul>
								        </div>
								        <div class="body">
								          <ul style="float: left">
								            <li><p>语文</p><span>{{scoreToGradeFormat gradeId chineseScore fullScore 0}}</span></li>
								            <li><p>英语</p><span>{{scoreToGradeFormat gradeId englishScore fullScore 2}}</span></li>
								            <li><p>数学</p><span>{{scoreToGradeFormat gradeId mathScore fullScore 1}}</span></li>
								            <li><p>总分</p><span>{{sumScore}}</span></li>
								          </ul>
								          <ul style="float: right">
								          	{{#each scoreAvgList}}
								            	<li><p><b>年级人平均分</b></p><span><b>{{avgScore}}</b></span></li>
								          	{{/each}}
								          </ul>
								        </div>
								      </div>
			                   	</div>
			                {{/each}}
		                    </script>
			            </div>
		            </div>
			        
	            </div>
	        </div>
	        
	        <div class="weui_tab kcfd-list1 hide" id="tab4">
	            
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd">
			                <div class="weui_media_box weui_media_small_appmsg">
				                <div class="weui_cells weui_cells_access" id="studentFruitList">
				                
				                </div>
			                </div>
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
	            </div>
	            <c:if test="${null != user.teacher }">
		            <a href="<%=basePath%>/ls/student/groupup/studentFruit/add/${studentId}">
			            <div class="addBtnnew">
							<div class="linea"></div>
							<div class="lineb"></div>
				        </div>
				    </a>
			    </c:if>
	        </div>
        </div>   
	</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	var isLoadStudentFruits = false, isLoadStudentScore = false;
	var sfPage = 0, sfRows = 5;
	var isLoadFinished = false, isLoadDListTable = false;
	var d_page = 1, y_page = 1, rows = 10;
	$(function() {
		$('#tab3').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		$('#tab4').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		$('#tab5').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		$(".tab3").click(function() {
			$(this).removeClass("m_gry").addClass("m_bull");
			$('.tab4').removeClass("r_bull").addClass("r_gry");
			$('.tab5').removeClass("l_bull").addClass("l_gry");
			$("#tab3").show();
			$("#tab4").hide();
			$("#tab5").hide();
			$('#addBtnnew').hide();
			if(!isLoadStudentScore) {
				isLoadStudentScore = true;
				initStudentScore();
			}
		});
		$(".tab4").click(function() {
			$(this).removeClass("r_gry").addClass("r_bull");
			$('.tab3').removeClass("m_bull").addClass("m_gry");
			$('.tab5').removeClass("l_bull").addClass("l_gry");
			$("#tab3").hide();
			$("#tab4").show();
			$("#tab5").hide();
			$('#addBtnnew').show();
			if(!isLoadStudentFruits) {
				isLoadStudentFruits = true;
				loadStudentFruits();
			}
		});
		$(".tab5").click(function() {
			$(this).removeClass("l_gry").addClass("l_bull");
			$('.tab3').removeClass("m_bull").addClass("m_gry");
			$('.tab4').removeClass("r_bull").addClass("r_gry");
			$("#tab3").hide();
			$("#tab4").hide();
			$("#tab5").show();
			$('#addBtnnew').hide();
		})
		var from = queryStringByName("to");
		if(from != null && from == 'award') {
			$(".tab4").click();
		}
		$("#tab3 .dropload-down").on("click", ".dropload-hasData", function() {
			loadStudentFruits();
		})
		$("#wyspList").click(function() {
			if(!isLoadFinished) loadMyWork(2, 'yListTable');
		})
		$("#tab5 .dropload-down").on("click", ".dropload-hasData", function() {
			var id = $(this).closest(".weui_tab_bd_item").find(".weui_cells").attr("id");
			if(id == 'dListTable') {
				loadMyWork(1, 'dListTable');
			}else if(id == 'yListTable') {
				loadMyWork(2, 'yListTable');
			}
		})
		loadMyWork(1, 'dListTable');
	});
	function loadStudentFruits(){
		sfPage+=1;
		$.ajax({
          	url : basePath + "/student/groupup/studentFruit/page/query",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			page: sfPage,
  	 			rows: sfRows,
  	 			studentId: "${studentId}"
  	 		},
            success: function(data){
            	if(data != null) {
            		var html = "";
					if(data.rows.length == 0 || sfPage*sfRows >= data.total) {// 如果没有数据
	            		 $("#studentFruitList").closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                }
					for(var i in data.rows) {
						var itm = data.rows[i];
						html += '<a class="weui_cell" href="<%=basePath%>${user.currUrl}/student/groupup/studentFruit/detail/'+itm.id+'?sid=${studentId}">\
			                   <div class="weui_cell_bd weui_cell_primary">\
								<h4 class="weui_media_title f-blue" style="white-space: inherit;">'+itm.competitionName+'</h4>\
								<p class="weui_media_desc mt10">参数学生：'+itm.studentName+'</p>\
								<p class="weui_media_desc mt5">指导老师：'+itm.guideTeacher+'</p>\
								<p class="weui_media_desc mt5">获奖时间：'+getTime(itm.awardTime, "yyyy-MM-dd")+'</p>\
				   			   </div>\
				   			   <span class="weui_cell_ft"></span>\
							</a>';
					}
					$("#studentFruitList").append(html);
            	}
            },
            error: function(xhr, type){
              
            }
         });
	}
	function initStudentScore(){
		$.ajax({
          	url : basePath + "/student/groupup/studentScore/query",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			studentId: "${studentId}"
  	 		},
            success: function(data){
            	if(data != null && data.length > 0) {
            		var result = {list: data};
            		loadStudentScoreHtml(result);
            	}
            },
            error: function(xhr, type){
              
            }
         });
	}
	function loadStudentScoreHtml(data) {
		var myTemplate = Handlebars.compile($("#studentScore-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
			if(v1 == v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		Handlebars.registerHelper("dateFormat", function(v1) {
			return getTime(v1, "yyyy/MM/dd hh:mm");
		});
		Handlebars.registerHelper("scoreToGradeFormat", function(gradeId, score, fullScore, idx) {
			return scoreToGrade(gradeId, score, fullScore, idx);
		});
		$('#scoreList').append(myTemplate(data));
	}

	function loadMyWork(isFinished, id) {
	   var params = {
		    status: isFinished,
			page: isFinished == 0 ? d_page : y_page,
			rows: rows	   
	   }
	   if("${user.roleType}" == 0) {
		   params.parentId = "${user.parent.id}";
	   }else {
		   params.studentId = "${studentId}";
	   }
	   $.ajax({
	     	url : basePath + "${user.currUrl}/week/comment/page",
	 		type : "post",
	 		dataType : "json",
	 		data : params,
	        success: function(data){
	        	if(data.rows.length == 0 || params.page*params.rows >= data.total) {// 如果没有数据
	        		$("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	            	if(data.rows.length == 0) return;
	            }
	        	isFinished == 0 ? d_page += 1 : y_page += 1
	       	  	loadOfficeHtml(data,isFinished);
	         },
	         error: function(xhr, type){
	             
	         }
	     });
	}
	function loadOfficeHtml(data,isFinished){
		var myTemplate = Handlebars.compile($("#office-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
			if(v1 == v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		Handlebars.registerHelper("feedbackFormat", function(v1,v2,options) {
			if(v1) return "";
			return "<a href='javascript:void(0)' onclick='feedback("+v2+")' class='wdgz-list-link-fk'>反馈</a>";
		});
		Handlebars.registerHelper("dateFormat", function(v1) {
			return getTime(v1, "yyyy-MM-dd hh:mm:ss");
		});
		if(isFinished == 1) $('#dListTable').append(myTemplate(data));
		else $('#yListTable').append(myTemplate(data));
	}
</script>
</html>